package com.eascs.ticket.configuration.service;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.eascs.site.tag.select.SelectDataService;
import com.eascs.ticket.common.service.BaseSevice;
import com.eascs.ticket.configuration.dao.SelectDataServiceDao;
import com.eascs.ticket.project.dao.ProjectDao;
import com.eascs.ticket.project.service.ProjectModuleService;
import com.eascs.ticket.ticket.service.TicketService;
import com.eascs.ticket.ticket.service.TicketVersionService;
import com.eascs.ticket.user.dao.UserDao;

@Service
public class SelectDataServiceImpl extends BaseSevice implements SelectDataService {
	@Inject
	private SelectDataServiceDao selectDataServiceDao;

	@Inject
	private TicketTypeService ticketTypeService;

	@Inject
	private DictionaryService dictionaryService;

	@Inject
	private TicketStatusService ticketStatusService;

	@Inject
	private UserDao userDao;

	@Inject
	private ProjectDao projectDao;

	@Inject
	private TicketAssociationTypeService ticketAssociationTypeService;

	@Inject
	private TicketService ticketService;

	@Inject
	private TicketVersionService ticketVersionService;

	@Inject
	private TicketTypeStatusService ticketTypeStatusService;

	@Inject
	private ProjectModuleService projectModuleService;

	public List<Object[]> getDataSouce(String dataSouceType, String dataSouceFrom) {
		if ("user".equals(dataSouceFrom)) {
			if ("validUser".equals(dataSouceType)) {
				return userDao.getValidUserDataSouceList();
			}
			if ("allUser".equals(dataSouceType)) {
				return userDao.getAllUserDataSouceList();
			}
		}
		if ("project".equals(dataSouceFrom)) {
			if ("validProject".equals(dataSouceType)) {
				return projectDao.getValidProjects();
			}
			if ("allProject".equals(dataSouceType)) {
				return projectDao.getAllProjects();
			}
		}

		if ("projectModule".equals(dataSouceFrom)) {
			return this.projectModuleService.getProjectModuleByProjectId(dataSouceType);
		}

		if ("projectModulePdr".equals(dataSouceFrom)) {
			return this.projectModuleService.getProjectModuleByNameCodeProjectId(dataSouceType);
		}

		if ("allProjectModul".equals(dataSouceType)) {
			return this.projectModuleService.getAllProjectModuleDataSouce();
		}

		if ("ticketType".equals(dataSouceType)) {
			return ticketTypeService.getTicketTypeDataSource();
		}

		if ("dictionaryType".equals(dataSouceType)) {
			return dictionaryService.getDictionaryTypeDataSource();
		}

		if ("ticketStatus".equals(dataSouceType)) {
			return ticketStatusService.getAllStatusDataSource();
		}

		if ("statusChangeDataSource".equals(dataSouceType)) {
			return this.ticketTypeStatusService.getStatusChangeDataSource();
		}

		if ("ticketAssociationType".equals(dataSouceFrom)) {
			if ("customTicketAssociationType".equals(dataSouceType)) {
				return this.ticketAssociationTypeService.getCustomTicketAssociationType();
			}
			if ("allTicketAssociationType".equals(dataSouceType)) {
				return this.ticketAssociationTypeService.getAllTicketAssociationType();
			}

		}

		if ("allProjectVersion".equals(dataSouceFrom)) {
			return ticketVersionService.getAllProjectVersionDataSource(dataSouceType);
		}

		if ("validProjectVersion".equals(dataSouceFrom)) {
			return ticketVersionService.getValidProjectVersionDataSource(dataSouceType);
		}

		if ("ticket".equals(dataSouceFrom)) {
			return ticketService.getTicketDataSource(dataSouceType);
		}

		if ("searchTicketOrderBy".equals(dataSouceType)) {
			List<Object[]> orders = new ArrayList<Object[]>();
			orders.add(new Object[] { "createDate", "创建日期" });
			orders.add(new Object[] { "dueDate", "到期日期" });
			orders.add(new Object[] { "operator", "经办人" });
			orders.add(new Object[] { "version", "版本" });
			orders.add(new Object[] { "status", "状态" });
			return orders;
		}

		return this.selectDataServiceDao.getDictionaryDataDataSouceList(dataSouceType);
	}

}
